home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
- import glob
- import os
- import subprocess
- from timedops import TimedSubprocess
- import urllib
- from base import *
-
- class CheckUSBPermissions(Question):
-
- def __init__(self, troubleshooter):
- Question.__init__(self, troubleshooter, 'Check USB permissions')
- troubleshooter.new_page(gtk.Label(), self)
-
-
- def display(self):
- self.answers = { }
- answers = self.troubleshooter.answers
- if answers['cups_queue_listed']:
- if answers['is_cups_class']:
- return False
- cups_printer_dict = answers['cups_printer_dict']
- device_uri = cups_printer_dict['device-uri']
- elif answers.get('cups_device_listed', False):
- device_uri = answers['cups_device_uri']
- else:
- return False
- (scheme, rest) = answers['is_cups_class'].splittype(device_uri)
- if scheme not in ('hp', 'hpfax', 'usb', 'hal'):
- return False
- LSUSB = '/sbin/lsusb'
- if not os.access(LSUSB, os.X_OK):
- return False
- GETFACL = '/usr/bin/getfacl'
- if not os.access(GETFACL, os.X_OK):
- return False
- parent = self.troubleshooter.get_window()
-
- try:
- self.op = TimedSubprocess(parent = parent, args = 'LC_ALL=C ' + LSUSB + ' -v', shell = True, stdin = file('/dev/null'), stdout = subprocess.PIPE, stderr = subprocess.PIPE)
- (lsusb_stdout, lsusb_stderr, result) = self.op.run()
- except:
- os.access(GETFACL, os.X_OK)
- os.access(LSUSB, os.X_OK)
- scheme not in ('hp', 'hpfax', 'usb', 'hal')
- return False
-
- dev_by_id = { }
- this_dev = None
- for line in lsusb_stdout:
- if this_dev != None:
- pass
- separators = [
- ('Bus ', 3),
- (' Device ', 3),
- (': ID ', 4),
- (':', 4),
- (' ', -1)]
- fields = []
- i = 0
- p = line
- while i < len(separators):
- (sep, length) = separators[i]
- if not p.startswith(sep):
- break
-
- start = len(sep)
- if length == -1:
- end = len(p)
- fields.append(p[start:])
- else:
- end = start + length
- fields.append(p[start:end])
- p = p[end:]
- i += 1
- if i < len(separators):
- continue
-
- if not scheme.startswith('hp') and fields[2] != '03f0':
- continue
-
- this_dev = {
- 'bus': fields[0],
- 'dev': fields[1],
- 'name': fields[4],
- 'full': line }
- this_mfr_id = fields[2]
- this_mdl_id = fields[3]
-
- infos = { }
- paths = []
- if not scheme.startswith('hp'):
- paths.extend(glob.glob('/dev/usb/lp?'))
-
- for mfr_id, mdls in dev_by_id.iteritems():
- for mdl_id, devs in mdls.iteritems():
- for dev in devs:
- path = '/dev/bus/usb/%s/%s' % (dev['bus'], dev['dev'])
- paths.append(path)
- infos[path] = dev['full']
-
-
-
- perms = []
- for path in paths:
-
- try:
- self.op = TimedSubprocess(parent = parent, args = 'LC_ALL=C %s %s' % (GETFACL, path), shell = True, stdin = file('/dev/null'), stdout = subprocess.PIPE, stderr = subprocess.PIPE)
- (getfacl_stdout, getfacl_stderr, result) = self.op.run()
- output = filter((lambda x: len(x) > 0), getfacl_stdout)
- except:
- output = []
-
- info = infos.get(path, path)
- perms.append((info, output))
-
- self.answers['getfacl_output'] = perms
- return False
-
-
- def collect_answer(self):
- return self.answers
-
-
- def cancel_operation(self):
- self.op.cancel()
-
-
-